<?php namespace Common\Model;
use Hdphp\Model\Model;
class administrator extends Model{
	protected $table = "administrator";
//	自动验证
protected $validate = array( 
        array('usename','required','用户名不能为空',3,3),
        array('usename','user:4,20','用户名为4-20位',3,3),
        array('password1','minlen:6','密码不得小于6位',3,3),
        array('password','confirm:password1','两次密码输入不一致',3,3),
        array('phone','phone ','请输入有效的手机号',3,3),
    ); 
	public function store(){
		//如果验证失败
		if(!$this->create()) return false;
		
		//判断验证码是否正确
		if(strtoupper(Q('post.code'))!= Code::get()) {
			$this->error='验证码错误！'; 
			return false;
		}
		$usename=Q('post.usename');
		$data=$this->where("usename='{$usename}'")->find();
		if($data){
			$this->error='用户名已存在！！';
			return false; 
		} 
		
		//验证成功
		$this->data['password']=md5(Q('post.password'));
		$this->add();
		//成功提示
		return true;
	} 
    
}
